package com.ldc.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldc.model.Article;
import com.ldc.model.Location;
import com.ldc.service.mapper.LocationMapper;
import com.ldc.service.service.LocationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能描述
 *
 * @author liudi
 * @since 2023/8/5
 */
@Service
public class LocationServiceImpl extends ServiceImpl<LocationMapper, Location> implements LocationService {
    @Override
    public List<Location> findListBy(LambdaQueryWrapper<Location> queryWrapper) {
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public int batchDeleteBy(LambdaQueryWrapper<Location> queryWrapper) {
        return getBaseMapper().delete(queryWrapper);
    }

    @Override
    public IPage<Location> findPageBy(int page, int limit, LambdaQueryWrapper<Location> queryWrapper) {
        return getBaseMapper().selectPage(Page.of(page, limit), queryWrapper);
    }

    @Override
    public IPage<Location> findPageByQuery(int page, int limit, String query) {
        return findPageBy(page, limit, new LambdaQueryWrapper<Location>()
                .eq(Location::getCountry, query)
                .or()
                .eq(Location::getProvince, query)
                .or()
                .eq(Location::getCity, query)
                .or()
                .like(Location::getAddress, query)
                .orderByDesc(Location::getChangeTime));
    }
}
